//
//  CommonViewController.m
//  deyingSoft
//
//  Created by GuiDaYou on 16/1/23.
//  Copyright © 2016年 李世飞. All rights reserved.
//

#import "LSF_CommonViewController.h"

@interface LSF_CommonViewController ()<UIGestureRecognizerDelegate>

@end

@implementation LSF_CommonViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor=[LSF_Util getColor:@"f2f2f2"];

    
    [self initNavView];
    [self initNavTitleView];
    [self addNavBackBtn];
    
  
    self.navigationController.interactivePopGestureRecognizer.delegate=self;
    self.automaticallyAdjustsScrollViewInsets=NO;
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
//    [self closeLoadingView];
}

-(void)initNavView
{
    //先隐藏系统的导航栏
    self.navigationController.navigationBarHidden=NO;
 
    navView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    navView.backgroundColor=white;
    [self.view addSubview:navView];

}
-(void)initNavTitleView
{
    navTitleLable=[LSF_Util labelName:nil fontSize:16.0 rect:CGRectMake(40, 22, self.view.frame.size.width-100, 40) View:navView Alignment:NSTextAlignmentCenter Color:orange Tag:0];
    navTitleLable.userInteractionEnabled=NO;
}

- (void)addNavBackBtn
{
    if (!isModal&&self.navigationController.viewControllers[0]==self) {
        return;
    }
    else
    {
       UIButton * backBtn= [LSF_Util buttonPhotoAlignment:nil hilPhoto:nil rect:CGRectMake(5, 22, 40, 40) title:0  Tag:0 View:navView textColor:nil Size:nil backgroundColor:nil];
        
        [backBtn addTarget:self action:@selector(actNavBack) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
}

-(void)actNavBack
{
    if (!isModal && self.navigationController) {
        //非模态视图
        if (HUD) {
            [HUD hide:true];
        }
        [self.navigationController popViewControllerAnimated:true];
    }else{
        [self dismissViewControllerAnimated:true completion:nil];
    }
}
#pragma mark - 设置Vc的title
-(void)setNavTitle:(NSString *)title
{
    navTitleLable.text=title;
}

#pragma mark - 导航栏2边按钮的响应处理方法
-(void)actNavLeftBtn
{
    //子类去实现
}

-(void)actNavRightBtn
{
    //子类去实现
}

#pragma mark - 添加导航栏左右按钮的方法(文本和图片)
-(void)addNavLeftBtnWithTitle:(NSString *)title
{
    navLeftBtn=[LSF_Util buttonPhotoAlignment:nil hilPhoto:nil rect:CGRectMake(10, 11, 66, 44) title:title  Tag:0 View:navView textColor:black Size:[UIFont systemFontOfSize:16.0] backgroundColor:nil];
    
    [navLeftBtn addTarget:self action:@selector(actNavLeftBtn) forControlEvents:UIControlEventTouchUpInside];

}

-(void)addNavLeftBtnWithTitle:(NSString *)title rect:(CGRect)rect
{
    navLeftBtn=[LSF_Util buttonPhotoAlignment:nil hilPhoto:nil rect:rect title:title Tag:0 View:navView textColor:white Size:[UIFont systemFontOfSize:16.0] backgroundColor:nil];
    [navLeftBtn addTarget:self action:@selector(actNavLeftBtn) forControlEvents:UIControlEventTouchUpInside];

}

-(void)addNavRightBtnWithTitle:(NSString *)title
{
    
    navRightBtn=[LSF_Util buttonPhotoAlignment:nil hilPhoto:nil rect:CGRectMake(ScreenW-76, 22, 66, 40) title:title Tag:0 View:navView textColor:black Size:font16 backgroundColor:nil];
    
    [navRightBtn addTarget:self action:@selector(actNavRightBtn) forControlEvents:UIControlEventTouchUpInside];
    

}
-(void)addNavRightBtnWithTitle:(NSString *)title color:(UIColor *)color
{
    navRightBtn=[LSF_Util buttonPhotoAlignment:nil hilPhoto:nil rect:CGRectMake(ScreenW-66-10,20, 66, 44) title:title Tag:0 View:navView textColor:color Size:font16 backgroundColor:nil];
    
    [navRightBtn addTarget:self action:@selector(actNavRightBtn) forControlEvents:UIControlEventTouchUpInside];

    
}

-(void)addNavRightBtnWithTitle:(NSString *)title color:(UIColor *)color rect:(CGRect)rect

{
    navRightBtn=[LSF_Util buttonPhotoAlignment:nil hilPhoto:nil rect:rect title:title  Tag:0 View:navView textColor:color Size:font16 backgroundColor:nil];
    [navRightBtn addTarget:self action:@selector(actNavRightBtn) forControlEvents:UIControlEventTouchUpInside];

    
}
-(void)addNavRightBtnWithTitle:(NSString *)title rect:(CGRect)rect
{
    navRightBtn=[LSF_Util buttonPhotoAlignment:nil hilPhoto:nil rect:rect title:title  Tag:0 View:navView textColor:[UIColor orangeColor] Size:font16 backgroundColor:nil];
    [navRightBtn addTarget:self action:@selector(actNavRightBtn) forControlEvents:UIControlEventTouchUpInside];

}

-(void)addNavLeftBtnWithImage:(NSString *)image rect:(CGRect)rect
{
    navLeftBtn=[LSF_Util buttonPhotoAlignment:image hilPhoto:image rect:rect title:nil  Tag:0 View:navView textColor:nil Size:nil backgroundColor:nil];
    
    [navLeftBtn addTarget:self action:@selector(actNavLeftBtn) forControlEvents:UIControlEventTouchUpInside];

    
}
-(void)addNavLeftBtnWithImage:(NSString *)image
{
    navLeftBtn=[LSF_Util buttonPhotoAlignment:image hilPhoto:image rect:CGRectMake(10, 20, 44, 44) title:nil Tag:0 View:navView textColor:nil Size:nil backgroundColor:nil];
    
    [navLeftBtn addTarget:self action:@selector(actNavLeftBtn) forControlEvents:UIControlEventTouchUpInside];

}
-(void)addNavRightBtnWithImage:(NSString *)image rect:(CGRect)rect
{
    navRightBtn=[LSF_Util buttonPhotoAlignment:image hilPhoto:image rect:rect title:nil Tag:0 View:navView textColor:nil Size:nil backgroundColor:nil];
    [navRightBtn addTarget:self action:@selector(actNavRightBtn) forControlEvents:UIControlEventTouchUpInside];

    
}
-(void)addNavRightBtnWithImage:(NSString *)image
{
    navRightBtn=[LSF_Util buttonPhotoAlignment:image hilPhoto:image rect:CGRectMake(ScreenW-44-10, 11, 44, 44) title:nil  Tag:0 View:navView textColor:nil Size:nil backgroundColor:nil];
    [navRightBtn addTarget:self action:@selector(actNavRightBtn) forControlEvents:UIControlEventTouchUpInside];

}

#pragma mark - 窗体加载进度条
- (void)showLoadingView
{
    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];
    
    if(loadingColor){
        HUD.color = loadingColor;
    }else{
        HUD.color = MS_RGBA(64, 64, 64, 0.7);
    }
//    
//    HUD.delegate = self;
//    HUD.delegate = self;
    HUD.labelText = @"加载中…";

    [HUD show:true];
}

- (void)closeLoadingView
{
    if (HUD) {
        [HUD hide:true];
    }
}


- (void)showMessage:(NSString*)message
{
    if(self && self.navigationController) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.mode = MBProgressHUDModeText;
        hud.detailsLabelText= message;
        hud.detailsLabelFont = [UIFont boldSystemFontOfSize:16.0f];
        hud.color = MS_RGBA(64, 64, 64, 0.8);
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:2];
    }
}


@end
